import router from "../../router/index";
import axios from 'axios';
const actions = {
  getJurisdictionList({
    state,
    commit
  }, params = {}) {
    let menus = new Promise((resolve, reject) => {
      return axios.get(state.adminBasic.API.selectMenuList, {
        params: Object.assign({}, params.data)
      }).then((res) => {
        if (res.data.status == 200) {
          commit("updateInfo", ["adminMenu", res.data.data.menuList]);
          if (res.data.
            data.menuList[0]) {
            router.push({
              name: res.data.data.menuList[0].url
            })
          }
          else{
            router.push({
              name: "nothing"
            })
          }

        } else {
          reject(res.data.message);
        }
      }).catch((err) => {
        reject(err.message);
      });
    })
    let btns = new Promise((resolve, reject) => {

      return axios.get(state.adminBasic.API.selectButtonList, {
        params: Object.assign({}, params.data)
      }).then((res) => {
        if (res.data.status == 200) {
          let arr = res.data.data;
          for (let i of Object.keys(arr)) {
            commit("addMapInfo", [i, "mapPowerList", arr[i]]);
          }
        } else {
          reject(res.data.message);
        }
      }).catch((err) => {
        reject(err.message);
      });
    })
    let bones = Promise.all([
      btns,
      menus
    ])
    return bones;
  }
}
export default actions;
